package com.peak.distribution.web.agent;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.peak.distribution.entity.agent.DisAgentAwardLog;
import com.peak.distribution.service.agent.DisAgentService;
import com.peak.distribution.vo.agent.DisAgentAwardLogVo;
import com.peak.spring.boot.api.repository.FilterParam;
import com.peak.spring.boot.api.repository.FilterParam.Operator;
import com.peak.spring.boot.api.web.JsonPage;
import com.peak.spring.boot.builder.repository.FilterParamBuilder;
import com.peak.spring.boot.builder.web.JsonBuilder;
import com.peak.spring.boot.core.web.BaseController;
import com.peak.spring.boot.tools.Servlets;

@RestController
@RequestMapping("/agent/award/log")
public class DisAgentAwardLogController extends BaseController<DisAgentAwardLog, DisAgentAwardLogVo> {
	
	@Autowired
	private DisAgentService agentService;

	@PostMapping("/my/list")
	public JsonPage list(HttpServletRequest request) {
		List<FilterParam> filterParams = FilterParamBuilder.create().parseRequest(request).build();
		filterParams.add(new FilterParam("account.agent.id", Operator.EQ,  agentService.getCurrentAgentId()));
		PageRequest pageRequest = Servlets.getPages(request);
		beforeList(request, filterParams, pageRequest);
		Page<DisAgentAwardLog> page = baseManager.findPage(filterParams, pageRequest);
		JsonPage json = JsonBuilder.page().success().page(page).convert(DisAgentAwardLogVo.class).build();
		json = afterList(json);
		return json;
	}
}
